home *** CD-ROM | disk | FTP | other *** search
Text File | 1987-12-14 | 20.5 KB | 648 lines | [TEXT/EDIT] |
- Material extracted from the TI Scheme Language Reference Manual
- with permission of the publisher
- Copyright 1985 Texas Instruments Incorporated
-
- [If you print this documentation or copy it onto another disk, be sure to
- include the above copyright and credit notice.]
-
- [The user-contributed implementation of SCOOPS that is distributed with
- MacScheme may not support all the features described in this documentation.
- We have changed the TI documentation only in places that obviously did not
- apply to the MacScheme version. Our omissions are indicated by ellipses,
- and our additions by square brackets -- Semantic Microsystems.]
-
- SCOOPS
-
- ALL-CLASSVARS
- ALL-INSTVARS
- ALL-METHODS
- CLASS-COMPILED?
- CLASS-OF-OBJECT
- CLASSVARS
- COMPILE-CLASS
- DEFINE-CLASS
- DEFINE-METHOD
- DELETE-METHOD
- DESCRIBE
- GETCV
- INSTVARS
- MAKE-INSTANCE
- METHODS
- MIXINS
- NAME->CLASS
- RENAME-CLASS
- SEND
- SEND-IF-HANDLES
- SETCV
-
- ----------------------------------------------------------------------
- ALL-CLASSVARS
-
- ALL-CLASSVARS returns a list of all the class variables in a SCOOPS class.
-
- Format: (ALL-CLASSVARS class)
-
- Parameter: class-- A SCOOPS class
-
- Explanation: ALL-CLASSVARS returns a list of the names of all the class
- variables in class, including the inherited class variables (if class is
- compiled or is in the inherited structure).To exclude the inherited class
- variables from the listing, use CLASSVARS.
-
- Example: Assume that the class employees exists (as shown in the example for
- DEFINE-CLASS) and that is has been compiled with the inherited class variable
- soc-sec-no.
-
- (all-classvars employees) --> (NO-OF-EMPLOYEES SOC-SEC-NO)
-
- ----------------------------------------------------------------------
- ALL-INSTVARS
-
- ALL-INSTVARS return a list of all the instance variables in a SCOOPS class.
-
- Format: (ALL-INSTVARS class)
-
- Parameter: class - A SCOOPS class
-
- Explanation: ALL-INSTVARS returns a list of the names of all the instance
- variables in class, including the inherited instance variables (if class is
- compiled or is in the inherited structure).
-
- To exclude the inherited instance variables from the listing, use INSTVARS.
-
- Examples: Assume that the class employees exists (as shown in the example for
- DEFINE-CLASS) and that it has been compiled with the inherited instance
- variable schools.
-
- (all-instvars employees) --> (SCHOOLS NAME EMP-NO MANAGER SALARY OVERTIME)
-
- ----------------------------------------------------------------------
- ALL-METHODS
-
- ALL-METHODS returns a list of all the methods of a SCOOPS class.
-
- Format: (ALL-METHODS class)
-
- Parameter: class - A SCOOPS class
-
- Explanation: ALL-METHODS returns a list of the names of all the methods of
- class, including the inherited methods (if class is compiled or is in the
- inherited structure) and the gettable and settable methods.
-
- Examples: Assume that the class employees exists (as shown in the example
- for DEFINE-CLASS) and that it has been compiled with the inherited instance
- variable schools.
-
- (all-methods employees) --> (GET-NAME GET-EMP-NO GET-NO-OF-EMPLOYEES
- GET-SALARY GET-SCHOOLS GET-SOC-SEC-NO
- SET-NAME SET-EMP-NO SET-MANAGER
- SET-OVERTIME SET-NO-OF-EMPLOYEES
- SET-SCHOOLS SET-SOC-SEC-NO)
-
- ----------------------------------------------------------------------
- CLASS-COMPILED?
-
- CLASS-COMPILED? determines whether a SCOOPS class has been compiled.
-
- Format: (CLASS-COMPILED? class)
-
- Parameter: class - A SCOOPS class
-
- Explanation: CLASS-COMPILED? returns true if class has been compiled and
- false, otherwise.
-
- To compile a SCOOPS class, use COMPILE-CLASS.
-
- Examples: Assume that the class employees exists and that it has not been
- compiled.
-
- (class-compiled? employees) --> false
-
- (compile-class emloyees) --> unspecified value
-
- (class-compiled? employees) --> true
-
- ----------------------------------------------------------------------
- CLASS-OF-OBJECT
-
- CLASS-OF-OBJECT returns the name of an object's SCOOPS class.
-
- Format: (CLASS-OF-OBJECT object)
-
- Parameter: object - an instance of a SCOOPS class
-
- Explanation: CLASS-OF-OBJECT returns the name of the class to which object
- belongs.
-
- Example: Assume that the class employees exists (as shown in the example
- for DEFINE-CLASS).
-
- (define emp1 (make-instance employees)) --> unspecified value
-
- (class-of-object emp1) --> EMPLOYEES
-
- ----------------------------------------------------------------------
- CLASSVARS
-
- CLASSVARS returns a list of the class variables defined in a SCOOPS class.
-
- Format: (CLASSVARS class)
-
- Parameter: class - A SCOOPS class
-
- Explanation: CLASSVARS returns a list of the names of the class variables in
- class. This list does not include the inherited class variables.
-
- To include the inherited class variables in the listing, use ALL-CLASSVARS.
-
- Examples: Assume that the class employees exists (as shown in the example
- for DEFINE-CLASS) and that it has been compiled with the inherited class
- variable soc-sec-no.
-
- (classvars employees) --> (NO-OF-EMPLOYEES)
-
- ----------------------------------------------------------------------
- COMPILE-CLASS
-
- COMPILE-CLASS compiles the given SCOOPS class.
-
- Format: (COMPILE-CLASS class)
-
- Parameter: class - A SCOOPS class
-
- Explanation: COMPILE-CLASS compiles class. An unspecified value is
- returned. The variables and methods of class are inherited from its mixins.
-
- Example: Assume that the class employees exists (as shown in the example for
- DEFINE-CLASS) and that it has not been compiled.
-
- (class-compiled? employees) --> false
-
- (compile-class employees) --> unspecified value
-
- (class-compiled? employees) --> true
-
- ----------------------------------------------------------------------
- DEFINE-CLASS
-
- DEFINE-CLASS defines a SCOOPS class.
-
- Format: (DEFINE-CLASS name (optional-attributes) ...)
-
- Parameters: name-The name of the SCOOPS class being defined.
-
- optional-attibutes...-The description of the SCOOPS class
- consisting of any of the following:
-
- CLASSVARS followed by the names of the class variables. A variable can be
- initialized by putting its name and initial value in a list. The initial
- value is evaluated when the class is compiled. If no initial value is
- specified, the variable remains unbound.
-
- INSTVARS followed by the names of the instance variables. A variable can be
- initialized by putting its name and initial value in a list. The initial
- value is evaluated when the instance of the class is created. The initial
- value for an instance variable could be an active value.
-
- MIXINS followed by the names of the component classes.
-
- OPTIONS followed by the keywords GETTABLE-VARIABLES, SETTABLE-VARIABLES, or
- INITTABLE-VARIABLES. These keywords can be given either with arguments that
- are class and instance variables or without arguments, in which case the
- keyword refers to all the class and instance variables. To associate
- arguments with a keyword, put the keyword and its arguments in a list.
-
- Explanation: DEFINE-CLASS defines a SCOOPS class, named name, consisting of
- optional-attributes. An unspecified value is returned.
-
- Note that instance variables can have active values associated with them.
- These values are declared in optional-attributes after the keyword INSTVARS
- as follows:
-
- (name (active init-value getfn setfn))
-
- The value init-value is the initial value of name. Whenever name is accessed
- with GET-name, the current value of name is passed to getfn (a procedure of
- one argument), and the value returned by getfn is the value returned by
- GET-name. Whenever the value of name is changed with SET-name, the new value
- is passed to setfn (a procedure of one argument), and the value returned by
- setfn is the new value of name. Active values may be nested to an arbitrary
- depth by specifying another active value as the init-value of an active value.
-
- Example: In this example, a class named employees is created. Its inherited
- classes will be personal-info and education-experience.
-
- (define-class employees
- (classvars (no-of-employees 0))
- (instvars name emp-no manager salary (overtime 0))
- (mixins personal-info education-experience)
- (options
- (gettable-variables name emp-no no-of-employees)
- settable-variables
- inittable-variables)) --> unspecified value
-
- ----------------------------------------------------------------------
- DEFINE-METHOD
-
- DEFINE-METHOD defines a method for a SCOOPS class.
-
- Format: (DEFINE-METHOD (class method) lambdalist body)
-
- Parameters: class - A SCOOPS class
- method - The name of the method being defined
- lambdalist - The list of the formal parameters of the method
- body - The body of the method
-
- Explanation: DEFINE-METHOD defines a method that determines the behavior of
- class. An unspecified value is returned. If a method with the same name
- exists already for class, this definition replaces the previous definition.
- Also, this definition applies to all subclasses of class.
-
- Example: This example defines a class named employees and its methods.
- Notice that name, emp-no, salary, and overtime are instance variables of
- employees and thus are accessed directly instead of by using the get methods.
-
- (define-class employees
- (classvars (no-of-employees 0))
- (instvars name emp-no manager salary (overtime 0))
- (mixins personal-info education-experience)
- (options
- (gettable-variables name emp-no no-of-employees)
- settable-variables
- inittable-variables)) --> unspecified value
-
- (define-method (employees earnings) ()
- (+ salary overtime)) --> unspecified value
-
- (define-method
- (employees earnings-greater-than) (val)
- (if (> (earnings) val)
- (writeln name " " emp-no)
- #f)) --> unspecified value
-
- (define emp1
- (make-instance employees
- 'name 'RALPH
- 'emp-no 001
- 'manager 'SAM
- 'salary 100)) --> unspecified value
-
- (send emp1 earnings-greater-than 99) --> false
- RALPH 1
-
- ----------------------------------------------------------------------
- DELETE-METHOD
-
- DELETE-METHOD deletes a method for a SCOOPS class.
-
- Format: (DELETE-METHOD (class method))
-
- Parameters: class - A SCOOPS class
-
- Explanation: DELETE-METHOD deletes method from class. An unspecified value
- is returned. If method is not defined in class, an error results. All the
- subclasses of class notice the deletion.
-
- Examples: Assume that the class employees exists (as shown in the example
- for DEFINE-CLASS) with the method earnings (as shown in the example for
- DEFINE-METHOD). The following example deletes the method earnings from
- employees:
-
- (delete-method (employee earnings)) --> unspecified value
-
- ----------------------------------------------------------------------
- DESCRIBE
-
- DESCRIBE prints the description of a SCOOPS class or SCOOPS object.
-
- Format: (DESCRIBE class-or-object)
-
- Parameter: class-or-object - A SCOOPS class or an instance of a SCOOPS class
-
- Explanation: DESCRIBE prints a description of class-or-object to the current
- output port. An unspecified value is returned.
-
- If class-or-object is a class, DESCRIBE prints the list of class variables,
- instance variables, and methods and tells wheter the class has been compiled
- and whether the class has been compiled and whether the class has been
- inherited.
-
- If class-or-object is an instance of a class, DESCRIBE prints the names and
- the values of the class as well as the instance variables.
-
- Example: Assume that the classes employees, personal-info, and
- education-experience exist, with personal-info having the single class
- variable soc-sec-no and education-experience having the instance variable
- schools.
-
- (describe employees)
-
- CLASS DESCRIPTION
-
- NAME : EMPLOYEES
- CLASSVARS : (SOC-SEC-NO NO-OF-EMPLOYEES)
- INSTANCE VARS : (SCHOOLS NAME EMP-NO MANAGER SALARY OVERTIME)
- METHODS : (SET-NO-OF-EMPLOYEES SET-NAME
- SET-EMP-NO SET-MANAGER SET-SALARY SET-OVERTIME
- SET-SOC-SEC-NO SET-SCHOOLS GET-NAME GET-EMP-NO
- GET-NO-OFEMPLOYEES GET-SOC-SEC-NO GET-SCHOOLS)
- MIXINS : (PERSONAL-INFO EDUCATION-EXPERIENCE)
- CLASS COMPILED : #T
- CLASS INHERITED : #T
-
- --> unspecified value
-
- ----------------------------------------------------------------------
- GETCV
-
- GETCV returns the value of a SCOOPS class variable.
-
- Format: (GETCV class var)
-
- Parameters: class-A SCOOPS class
- var-The name of a class variable defined in class
-
- Explanation: GETCV returns the value of var in class. If class has not been
- compiled or var has not been described as gettable in DEFINE-CLASS, an error
- results.
-
- Examples: Assume that the class employees has been defined (as shown in the
- example for DEFINE-CLASS).
-
- (setcv employees no-of-employees 1000) --> unspecified value
-
- (getcv employees no-of-employees) --> 1000
-
- ----------------------------------------------------------------------
- INSTVARS
-
- INSTVARS returns a list of the instance variables defined in a SCOOPS class.
-
- Formats: (INSTVARS class)
-
- Parameter: class-A SCOOPS class
-
- Explanation: INSTVARS returns a list of the names of the instance variables
- defined in class. This list does not inclued the inherited instance
- variables.
-
- To inclued the inherited instance variables in the listing, use the procedure
- ALL-INSTVARS.
-
- Examples: Assume that the class employees exists as shown in the example for
- DEFINE-CLASS.
-
- (instvars employees) --> (NAME EMP-NO MANAGER SALARY OVERTIME)
-
- ----------------------------------------------------------------------
- MAKE-INSTANCE
-
- MAKE-INSTANCE creates an instance of a SCOOPS class.
-
- Format: (MAKE-INSTANCE class var init-val . . .)
-
- Parameters: class-A SCOOPS class
- var . . .-The variables in class whose values are to be
- initialized
- init-val . .-The initial values for each var
-
- Explanation: MAKE-INSTANCE evaluates var and init-val and then returns an
- instance of class, which is an environment. This special form can be used to
- specify initial values for instance variables that have been described as
- itittable in DEFINE-CLASS.
-
- Example:
-
- (define-class employees
- (classvars (no-of-employees ))
- (instvars name emp-no manager salary (overtime ))
- (mixins personal-info education-experience)
- (options
- (gettable-variables name emp-no no-of-employees)
- settable-variables
- inittable-variables)) --> unspecified value
-
- (define-method (employees earnings) ()
- (+ salary overtime)) --> unspecified value
-
- (define-method
- (employees earnings-greater-than) (val)
- (if (>? (earnings) val)
- (writeln name " " emp-no)
- #F)) --> unspecified value
-
- (define emp1
- (make-instance employees
- 'name 'RALPH
- 'emp-no 001
- 'manager 'SAM
- 'salary 100)) --> unspecified value
-
- (send emp1 earnings-greater-than 99) --> false
- RALPH 1
-
- ----------------------------------------------------------------------
- METHODS
-
- METHODS returns a list of the methods defined in a SCOOPS class.
-
- Format: (METHODS class)
-
- Parameter: class - A SCOOPS class
-
- Explanation: METHODS returns a list of the names of the methods defined in
- class. This list does not included the inherited methods.
-
- To include the inherited methods in the listing, use ALL-METHODS.
-
- Example: Assume that the class employees exists (as shown in the example for
- DEFINE-CLASS) and that it has been compiled with the inherited instance
- variable schools and the inherited class variable soc-sec-no.
-
- (methods employees) --> (GET-NAME GET-EMP-NO GET-NO-OF-EMPLOYEES
- GET-SALARY SET-EMP-NO SET-MANAGER SET-OVERTIME
- SET-NO-OF-EMPLOYEES)
-
- ----------------------------------------------------------------------
- MIXINS
-
- MIXINS returns a list of the mixins of a SCOOPS class.
-
- Format: (MIXINS class)
-
- Parameter: class-A SCOOPS class.
-
- Explanation: MIXINS returns a list of the mixins of class.
-
- Examples: Assume that the class employees exists (as shown in the example
- for DEFINE-CLASS).
-
- (mixins employees) --> (PERSONAL-INFO EDUCATION-EXPERIENCE)
-
- ----------------------------------------------------------------------
- NAME->CLASS
-
- NAME->CLASS returns the SCOOPS class with the specified name.
-
- Format: (NAME->CLASS class)
-
- Parameter: class-The name of a SCOOPS class
-
- Explanation: NAME->CLASS returns the SCOOPS class with the name class.
-
- Example: Assume that the class employees exists (as shown in the example for
- DEFINE-CLASS).
-
- (name->class 'employees) --> scoops-class
-
- ----------------------------------------------------------------------
- RENAME-CLASS
-
- RENAME-CLASS renames a SCOOPS class.
-
- Format: (RENAME-CLASS (class new-name))
-
- Parameters: class-A SCOOPS class
- new-name-The new name for the SCOOPS class
-
- Explanation: RENAME-CLASS renames class as new-name. An unspecified value
- is returned.
-
- Examples: Assume that the class employees exists ( as shown in the example
- for DEFINE-CLASS).
-
- (rename-class (employees slaves)) unspecified value
-
- ----------------------------------------------------------------------
- SEND
-
- SEND sends a message to an object in a SCOOPS class
-
- Format: (SEND object msg arg ...)
-
- Parameters: object - An instance of a SCOOPS class
- msg - The name of the message to be sent
- arg... - The arguments to the method associated with the message
-
- Explanation: SEND sends msg to object, applies the method associated with
- msg to the arguments (arg . . .), and returns the result of the application.
- SEND evaluates object and its arguments (arg . . .) but does not evaluated
- msg. The maximum number of arguments to the method that can be specified in
- SEND is 8. If object cannot handle msg, an error results.
-
- See also SEND-IF-HANDLES.
-
- Examples:
-
- (define-class employees
- (classvars (no-of-employees 0))
- (instvars name emp-no manager salary (overtime 0))
- (mixins personal-info education-experience)
- (options
- (gettable-variables name emp-no no-of-employees)
- settable-variables
- inittable-variables)) --> unspecified value
-
- (define-method (employees earnings) ()
- (+ salary overtime)) --> unspecified value
-
- (define-method
- (employees earnings-greater-than) (val)
- (if (>? (earnings) val)
- (writeln name " " emp-no)
- #F)) --> unspecified value
-
- (define emp1
- (make-instance employees
- 'name 'RALPH
- 'emp-no 001
- 'manager 'SAM
- 'salary 100)) --> unspecified value
-
- (send emp1 get-name) --> RALPH
-
- (send emp1 earnings) --> 100
-
- (send emp1 set-overtime 100) --> unspecified value
-
- (send emp1 earnings) --> 200
-
- ----------------------------------------------------------------------
- SEND-IF-HANDLES
-
- SEND-IF-HANDLES sends a message to a SCOOPS object only if the object can
- handle the message.
-
- Format: (SEND-IF-HANDLES object msg arg . . .)
-
- Parameters: object - An instance of a SCOOPS class
- msg - The name of the message to be sent
- arg ...- The arguments to the method associated with the message
-
- Explanation: SEND-IF-HANDLES sends msg to object only if object can handle
- msg, applies the method associated with msg to the arguments (arg...), and
- returns the result of the application. SEND-IF-HANDLES evaluates object and
- its arguments (arg...)‚ but does not evaluate msg. The maximum number of
- arguments to the method that can be specified in SEND-IF-HANDLES is 8. If
- object cannot handle msg, false is returned.
-
- See also SEND.
-
- Examples:
-
- (define-class employees
- (classvars (no-of-employees 0))
- (instvars name emp-no manager salary (overtime 0))
- (mixins personal-info education-experience)
- (options
- (gettable-variables name emp-no no-of-employees)
- settable-variables
- inittable-variables)) --> unspecified value
-
- (define-method (employees earnings) ()
- (+ salary overtime)) --> unspecified value
-
- (define-method
- (employees earnings-greater-than) (val)
- (if (>? (earnings) val)
- (writeln name " " emp-no)
- #F)) --> unspecified value
-
- (define emp1
- (make-instance employees
- 'name 'RALPH
- 'emp-no 001
- 'manager 'SAM
- 'salary 100)) --> unspecified value
-
- (send-if-handles emp1 get-name) --> RALPH
-
- (send-if-handles emp1 earnings) --> 100
-
- (send-if-handles emp1 set-overtime 100) --> unspecified value
-
- (send-if-handles emp1 get-value) --> false
-
- ----------------------------------------------------------------------
- SETCV
-
- SETCV changes the value of a SCOOPS class variable.
-
- Format: (SETCV class var exp)
-
- Parameters: class - A SCOOPS class
- var - The name of a class variable defined in class
- exp - The value to be stored in var
-
- Explanation: SETCV stores the value of exp in the var in class. An
- unspecified value is returned. If class has not been compiled or var has not
- been described as settable in DEFINE-CLASS, an error results.
-
- Examples: Assume that the class employees has been defined as shown in the
- example for DEFINE-CLASS.
-
- (setcv employees no-of-employees 1000) --> unspecified value
-
- (getcv employees no-of-employees) --> 1000
-
-